package com.padakeji.android.pworks.ui;

import android.app.Application;
import android.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

/**
 * Created by atanl on 15/5/10.
 */
public class UIHelper {

    private Context mContext;
    private Handler mHandler;

    public UIHelper(Context context) {
        mContext = context;
        mHandler = new Handler(Looper.getMainLooper());
    }
    public void showToast(final String text, final int duration) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(mContext, text, duration).show();
            }
        });
    }

    public void alertDialogFragment(final DialogFragment frag) {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                AlertWrapperActivity.setShowingFrag(frag);
                Intent i = new Intent(mContext, AlertWrapperActivity.class);
                i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                mContext.startActivity(i);
            }
        });
    }

}
